package com.hxd.otc.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.constraint.ConstraintLayout;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.utils.ResourceUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by lzy on 2018/9/18 0018.
 * description ${添加联系人地址条目view}
 */
public class ModifyWalletContactAddressView extends ConstraintLayout {
    @BindView(R.id.tv_coin_address)
    TextView mTvCoinAddress;
    @BindView(R.id.et_address)
    EditText mEtAddress;
    private String mCoinType = "";
    private OnScanClickListener mOnScanClickListener;

    public ModifyWalletContactAddressView(Context context) {
        this(context, null);
    }

    public ModifyWalletContactAddressView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ModifyWalletContactAddressView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        CharSequence coinType = null;
        if (attrs != null) {
            TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ModifyWalletContactAddressView, defStyleAttr, 0);
            coinType = a.getText(R.styleable.ModifyWalletContactAddressView_coinType);
            a.recycle();
        }

        LayoutInflater.from(context).inflate(R.layout.item_modity_wallet_contact_address, this);
        ButterKnife.bind(this);

        updateCoinType(coinType);
    }

    public void updateCoinType(CharSequence coinType) {
        mCoinType = TextUtils.isEmpty(coinType) ? "" : coinType.toString();
        mTvCoinAddress.setText(ResourceUtil.getString(R.string.data_address, mCoinType));
        mEtAddress.setHint(ResourceUtil.getString(R.string.please_input_coin_address, mCoinType));
    }

    public String getCoinType() {
        return mCoinType;
    }

    public String getAddress() {
        return mEtAddress.getText().toString().trim();
    }

    @OnClick(R.id.iv_scan)
    public void OnClick() {
        if (mOnScanClickListener != null)
            mOnScanClickListener.onScanClick(this);
    }

    public interface OnScanClickListener {
        void onScanClick(View view);
    }
}
